function numerico(){
	return "0123456789";
}
function decimal(){
	return "0123456789.";
}
function setEstyle(){
	
	$(".v-loading-indicator,.v-loading-indicator-delay,.v-loading-indicator-wait").css({
		   "width": "100%",
	   	   "height": "100%",
		   "margin": "0" ,
		   "background-position": "50%"  ,
		   "background-color": "gray"  ,
		   "background-repeat": "no-repeat"  ,
		   "background-attachment": "fixed"  , 
		   "opacity": ".8"  ,
		   "-ms-filter": "alpha(opacity=80)"  ,
		   "filter": "alpha(opacity=80)"});

}
function esTeclaEspecial(e){
	var BACKSPACE=8;
	var SUPR=46;
	var TAB		=9;
	var ENTER	=13;
	var CTRL	=17;
	var ALT		=18;
	var C	=99;
	var V	=118;
	var X	=120;
	
	var code = (e.keyCode ? e.keyCode : e.which);
	if((code >= 35 && code < 39) 
			|| code == BACKSPACE
			|| code == SUPR
			|| code == TAB
			|| code == ENTER
			|| code == CTRL
			|| code == ALT
			|| (e.ctrlKey && code == C)
			|| (e.ctrlKey && code == V)
			|| (e.ctrlKey && code == X)){return true;}
	if(code==39){
		var k = String.fromCharCode(e.which);
		if(k=="'"){return false;}
		else {return true;}
	}
	return false;
}
function esTeclaEspecialBorrar(e){
	var TAB		=9;
	var ENTER	=13;
	var CTRL	=17;
	var ALT		=18;
	var C	=99;
	var V	=118;
	var X	=120;
	
	var code = (e.keyCode ? e.keyCode : e.which);
	if((code >= 35 && code < 39) 
			|| code == TAB
			|| code == ENTER
			|| code == CTRL
			|| code == ALT
			|| code == 16
			|| (e.ctrlKey && code == C)
			|| (e.ctrlKey && code == V)
			|| (e.ctrlKey && code == X)
			|| (e.shiftKey && code == 37)
			|| (e.shiftKey && code == 39)){return true;}
	if(code==39){
		var k = String.fromCharCode(e.which);
		if(k=="'"){return false;}
		else {return true;}
	}
	return false;
}
function tamano(e,cod){
	var cadenaAnt = $(cod).val();
	if($(cod).attr("id")!=null){
		var tamId = $(cod).attr("id").split(",");
		var longitud;
			if(tamId.length==2){
				longitud=tamId[1];
				if(cadenaAnt.length>=longitud){
					e.preventDefault();
				}
			}
	}
}
$(document).ready(function() {
	$("body").delegate(".monto","keypress", function(e) {
		if(esTeclaEspecial(e)){return;}
		tamano(e,this);
		var cadena=decimal();
		var k = String.fromCharCode(e.which);
		var valor=$(this).val();
		if(k=="." && valor.indexOf(k)!=-1){
			e.preventDefault();
		}else{
			if(cadena.indexOf(k)==-1){
				e.preventDefault();
			}
		}
	});
	$("body").delegate(".monto","keyup", function(e) {
		if(esTeclaEspecialBorrar(e)){return;}
		if($(this).val().length!=0){
			var pos = $(this).caret();
			var validacion=false;
			if(pos!=$(this).val().length){
				validacion=true;
			}
			valor=$(this).val();
			valor=valor.replace(',','');
			var valorDecimal=valor.split('.');
			valor=$.number(valorDecimal[0]);
			if(valorDecimal.length==2){
				valor=valor+"."+valorDecimal[1];
			}
			$(this).val(valor);
			if(validacion){
				$(this).caret(pos);
			}
		}
	});
	$("body").delegate(".montoD","keypress", function(e) {
		if(esTeclaEspecial(e)){return;}
		tamano(e,this);
		var cadena=decimal();
		var k = String.fromCharCode(e.which);
		var valor=$(this).val();
		if(k=="." && valor.indexOf(k)!=-1){
			e.preventDefault();
		}else{
			if(cadena.indexOf(k)==-1){
				e.preventDefault();
			}else{
				var x = parseFloat(valor+k);
				if (isNaN(x) || x < 0 || x > 100) {
					e.preventDefault();
				}else{
					valor=valor+k;
					var valorDecimal=valor.split('.');
					if(valorDecimal.length==2 && valorDecimal[1].length>2){
						e.preventDefault();
					}
				}
			}
		}
	});
	/*$("body").delegate(".montoD","keyup", function(e) {
		if(esTeclaEspecialBorrar(e)){return;}
		if($(this).val().length!=0){
			var pos = $(this).caret();
			var validacion=false;
			if(pos!=$(this).val().length){
				validacion=true;
			}
			valor=$(this).val();
			var valorDecimal=valor.split('.');
			valor=valorDecimal[0];
			if(valorDecimal.length==2){
				valor=valor+"."+valorDecimal[1];
			}
			$(this).val(valor);
			if(validacion){
				$(this).caret(pos);
			}
		}
	});*/
	$("body").delegate(".decimal","keypress", function(e) {
		if(esTeclaEspecial(e)){return;}
		tamano(e,this);
		var cadena=decimal();
		var valor=$(this).val();
		var k = String.fromCharCode(e.which);
		if(k=="." && valor.indexOf(k)!=-1){
			e.preventDefault();
		}
		if(cadena.indexOf(k)==-1){
			e.preventDefault();
		}
	});
	$("body").delegate(".numerico","keypress", function(e) {
		if(esTeclaEspecial(e)){return;}
		tamano(e,this);
		var cadena=numerico();
		var k = String.fromCharCode(e.which);
		if(cadena.indexOf(k)==-1){
			e.preventDefault();
		}
	});
	
	$("body").delegate("[class*=numerico]","keypress", function(e) {
		var className = $("[class*=numerico]").attr('class');
			var pos=className.indexOf("numerico");
			var cadena = className.substring(pos);
			var vacio=className.indexOf(" ");
			var cadenaStylo = cadena.substring(0,vacio-1);
			var ultima = cadenaStylo.indexOf("o");
			var longitud = cadenaStylo.substring(ultima+1);
			
			if(esTeclaEspecial(e)){return;}		
			var cadenaAnt = $(this).val();
			if(cadenaAnt.length>=longitud){
				e.preventDefault();
			}
			var cadena=numerico();
			var k = String.fromCharCode(e.which);
			if(cadena.indexOf(k)==-1){
				e.preventDefault();
			}
	});
	
	$("body").delegate("[class*=strinngo]","keypress", function(e) {
		var className = $("[class*=strinngo]").attr('class');
			var pos=className.indexOf("strinngo");
			var cadena = className.substring(pos);
			var vacio=className.indexOf(" ");
			var cadenaStylo = cadena.substring(0,vacio-1);
			var ultima = cadenaStylo.indexOf("o");
			var longitud = cadenaStylo.substring(ultima+1);
			
			if(esTeclaEspecial(e)){return;}		
			var cadenaAnt = $(this).val();
			if(cadenaAnt.length>=longitud){
				e.preventDefault();
			}
			
	});
	
	
	/*$("body").delegate(".numerico8","keypress", function(e) {
		if(esTeclaEspecial(e)){return;}		
		var cadenaAnt = $(this).val();
		if(cadenaAnt.length>=8){
			e.preventDefault();
		}
		var cadena=numerico();
		var k = String.fromCharCode(e.which);
		if(cadena.indexOf(k)==-1){
			e.preventDefault();
		}
	});
	$("body").delegate(".numerico11","keypress", function(e) {
		if(esTeclaEspecial(e)){return;}
		var cadenaAnt = $(this).val();
		if(cadenaAnt.length>=11){
			e.preventDefault();
		}
		var cadena=numerico();
		var k = String.fromCharCode(e.which);
		if(cadena.indexOf(k)==-1){
			e.preventDefault();
		}
	});*/
	$("body").delegate(".textarea","keypress", function(e) {
		tamano(e,this);
	});
	/*$("body").delegate(".decimal","contextmenu", function(e) {
//		e.preventDefault();
	});*/
	/*$("body").delegate(".numerico","contextmenu", function(e) {
//		e.preventDefault();
	});*/
	/*$("body").delegate(".textarea","contextmenu", function(e) {
//		e.preventDefault();
	});*/
	
	
	/*$("body").delegate(".decimal","paste", function(e) {
//		e.preventDefault();
	});*/
	/*$("body").delegate(".numerico","paste", function(e) {
//		e.preventDefault();
	});*/
	/*$("body").delegate(".textarea","paste", function(e) {
//		e.preventDefault();
	
		
		var valor = $(this).val();
		alert(valor);
		var $this = $(this);
		var tamId = $(this).attr("id").split(",");
		var longitud;
		longitud=tamId[1];
		var corregido="";
		//save reference to element for use laster
		 setTimeout(function(){ //break the callstack to let the event finish
			    alert($this.val()); //read the value of the input field
			    var long=$this.val().length;
			    var long2=valor.length;
			    var paste=$this.val().substring(long,long2)
			    alert(paste);
			    corregido =$this.val().substring(0,longitud);
			    alert(corregido);
			    $(this).val(corregido);
			  },0);
		 
	});*/
	
});